package com.leyou.page.web;

import com.leyou.page.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Map;

/**
 * @author 虎哥
 */
@Controller
public class PageController {

    @Autowired
    private PageService pageService;

    /**
     * 跳转到商品详情页
     *
     * @param id
     * @return
     */
    @GetMapping("/item/{id}.html")
    public String toItemHtml(@PathVariable("id") Long id, Model model) {
        // 根据id查询商品信息
        Map<String, Object> itemData = pageService.loadItemData(id);
        // 把商品信息，加入model
        model.addAllAttributes(itemData);
        // 返回视图名称
        return "item";
    }
}
